<%@ page import="java.util.ArrayList" %>
<%@ page import="com.bean.Student" %><%--
  Created by IntelliJ IDEA.
  User: 20493
  Date: 2023/10/26
  Time: 16:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:useBean id="stu_DAO" class="com.dao.studentDAO"/>

<%
  request.setCharacterEncoding("utf-8");
  String keyword=request.getParameter("keyword");
  request.setAttribute("keyword",keyword);
  ArrayList<Student> students= stu_DAO.getByName(keyword);
  request.setAttribute("students",students);
%>
<html>
  <head>
    <title>学生信息</title>
  </head>
  <body>
  <form action="index.jsp" method="post">
    <input type="text" name="keyword" size="80" value="${requestScope.keyword}">
    <input type="submit" value="搜索">
  </form>
  <br>
  <button onclick="window.open('add.jsp')">添加学生</button>

  <table border="1">
    <tr>
      <th>ID</th>
      <th>姓名</th>
      <th>性别</th>
      <th>年龄</th>
      <th>手机号码</th>
      <th>专业</th>
      <th>班级</th>
    </tr>
    <c:forEach items="${students}" var="student">
      <tr>
        <td>${student.id}</td>
        <td>${student.name}</td>
        <td>${student.gender}</td>
        <td>${student.age}</td>
        <td>${student.phone}</td>
        <td>${student.major}</td>
        <td>${student.classes}</td>
        <td><a href="handle.jsp?action=edit&id=${student.id}">修改</a>
          <a href="javascript:void(0);" onClick="deleteBook(${student.id})">删除</a>

        </td>
      </tr>
    </c:forEach>
  </table>

  </body>
<script type="text/javascript">
  function deleteBook(id){
    if (confirm("你确定要删除该记录吗")==true)
      window.location="handle.jsp?action=delete&id="+id;
  }



</script>
</html>
